
update nf 
set nf.OrderId = nfn.OrderId, nf.StatusId = 2, nf.StatusChangeDate = isnull(o.Finished, o.Created)
from [dbo].[NotarialForm] nf 
inner join [dbo].[NotarialFormNumber] nfn on upper(rtrim(ltrim(nfn.[Name]))) like '%'+rtrim(ltrim(nf.Search))+'%'
inner join [dbo].[Order] as o on o.Id = nfn.OrderId 

update [dbo].[NotarialFormRange]
   SET [CreateDate] = '2010-01-01'

